/**
 * @file      ac_tlm_router.cpp
 * @author    Rafael Ghussn Cano
 * 
 * @brief     Implements a ac_tlm counter.
 */

//////////////////////////////////////////////////////////////////////////////

#ifndef AC_TLM_COUNTER_H_
#define AC_TLM_COUNTER_H_

//////////////////////////////////////////////////////////////////////////////

// Standard includes
// SystemC includes
#include <systemc>
// ArchC includes
#include "ac_tlm_protocol.H"

//////////////////////////////////////////////////////////////////////////////

// using statements
using tlm::tlm_transport_if;

//////////////////////////////////////////////////////////////////////////////

/// Namespace to isolate memory from ArchC
namespace user
{

/// A TLM counter
class ac_tlm_counter :
  public sc_module,
  public ac_tlm_transport_if // Using ArchC TLM protocol
{
public:

  /// Exposed port with ArchC interface
  sc_export< ac_tlm_transport_if > target_export;
  /// Internal read
  ac_tlm_rsp_status readm( uint32_t & );
  
  /**
   * Implementation of TLM transport method that
   * handle packets of the protocol doing apropriate actions.
   * This method must be implemented (required by SystemC TLM).
   * @param request is a received request packet
   * @return A response packet to be send
  */
  ac_tlm_rsp transport( const ac_tlm_req &request ) {

    ac_tlm_rsp response;
    response.status = readm( response.data );

    return response;
  }

  ac_tlm_counter( sc_module_name module_name);

private:
  volatile uint32_t c;

};

};

#endif //AC_TLM_COUNTER_H_
